package com.transaction.manage.controller;

import com.transaction.common.base.BaseController;
import com.transaction.common.base.PageInfo;
import com.transaction.common.util.ParamsUtil;
import com.transaction.manage.model.dto.ChannelInfo;
import com.transaction.manage.model.dto.MarketDate;
import com.transaction.manage.model.vo.MarketDateVo;
import com.transaction.manage.service.BaseParamsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/baseParams")
@ApiIgnore
public class BaseParamsController extends BaseController {

    private static Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private BaseParamsService baseParamsService;


    /**
     * 查询当前年份和市场下的市场交易日期
     * @return
     */
    @RequestMapping("/selectMarketDates")
    public Object selectMarketDates(HttpServletRequest request){
        MarketDate marketDate = ParamsUtil.getBeanParam(new MarketDate(),request);
        List<MarketDate> marketDateList = baseParamsService.selectMarketDates(marketDate);
        return retResultVo(marketDateList);
    }

    /**
     * 保存市场交易日
     * @param marketDateVo 保存的市场交易日对象
     * @return
     */
    @RequestMapping("/saveMarketDates")
    public Object saveMarketDates(@RequestBody MarketDateVo marketDateVo){
        baseParamsService.saveMarketDates(marketDateVo);
        return retResultVo("保存成功！");
    }

    /**-----------------------------------------channel-info-----------------------------------------------**/

    /**
     * 查询渠道信息集合
     * @param request
     * @return
     */
    @GetMapping("/selectChannelInfoList")
    public Object selectChannelInfoList(HttpServletRequest request){
        ChannelInfo channelInfo = ParamsUtil.getBeanParam(new ChannelInfo(),request);
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        List<ChannelInfo> channelInfoList = baseParamsService.selectChannelInfoList(channelInfo,pageInfo);
        pageInfo.setPageResult(channelInfoList);
        return pageInfo;
    }

    /**
     * 保存渠道信息
     * @param channelInfo 渠道信息
     * @return
     */
    @PostMapping("/saveChannelInfo")
    public Object saveChannelInfo(@RequestBody ChannelInfo channelInfo){
        baseParamsService.saveChannelInfo(channelInfo);
        return retResultVo("保存成功！");
    }

    /**
     * 删除渠道
     * @param channelInfo
     * @return
     */
    @PostMapping("/deleteChannelInfo")
    public Object deleteChannelInfo(@RequestBody ChannelInfo channelInfo){
        baseParamsService.deleteChannelInfo(channelInfo.getChannelCode());
        return retResultVo("删除成功！");
    }

    /**
     * 复核渠道
     * @param channelInfo
     * @return
     */
    @PostMapping("/checkChannelInfo")
    public Object checkChannelInfo(@RequestBody ChannelInfo channelInfo){
        baseParamsService.checkChannelInfo(channelInfo.getChannelCode());
        return retResultVo("复核成功！");
    }

    /**
     * 查询channelModal页面所有的下拉
     * @return
     */
    @GetMapping("/selectChannelInfoModalAllCombobox")
    public Object selectChannelInfoModalAllCombobox(){
        Map<String,Object> map = baseParamsService.selectChannelInfoModalAllCombobox();
        return retResultVo(map);
    }

    /**-----------------------------------------channel-info-----------------------------------------------**/


}
